package org.xiaoyu.rpc;

import com.xiaoyu.context.support.ClassPathXmlApplicationContext;
import com.xiaoyu.stereotype.Component;
import org.xiaoyu.rpc.common.constant.SystemPropertiesKey;
import org.xiaoyu.rpc.common.extension.ExtensionLoader;
import org.xiaoyu.rpc.config.PropertiesConfig;
import org.xiaoyu.rpc.postProcessor.RpcClientBeanProxyPostProcessor;
import org.xiaoyu.rpc.registry.Registry;
import org.xiaoyu.rpc.registry.RegistryFactory;
import org.xiaoyu.rpc.remoting.RemotingServer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import static org.xiaoyu.rpc.config.PropertiesConfig.properties;

/**
 * Created By Have
 * 2021/7/13 13:27
 */
@Component
public class ServerContainer {
    public static final RemotingServer server = ExtensionLoader.getExtensionLoader(RemotingServer.class).getDefaultExtension();

    private static final String RESOURCES_PROPERTIES = "/application.properties";


    public void init() {
        InputStream in = this.getClass().getResourceAsStream(RESOURCES_PROPERTIES);
        try {
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] xmls = new String[2];
        xmls[0] = "classpath:rpc.xml";
        xmls[1] = "classpath:spring.xml";
        new ClassPathXmlApplicationContext(xmls);
        server.init(Integer.valueOf(properties.getProperty(SystemPropertiesKey.SERVER_PORT)));
        server.start();
    }
}
